package cn.eric.bookstore.controller;


import cn.eric.framework.ajax.AjaxResponse;
import cn.eric.framework.exception.domain.exception.BusinessException;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@Transactional
public class DemoController {
    @RequestMapping(value = "/**", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResponse<Date> test() {
        return new AjaxResponse<>(new Date());
    }

    @RequestMapping(value = "/test/exception", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResponse<String> exceptionTest() {
        throw new BusinessException(10000);
    }

    @RequestMapping(value = "/test/500", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResponse<String> exception500Test() {
        int tmp = 100 / 0;
        return new AjaxResponse<>("hello world");
    }
}
